package com.ysd.gulimall.order.web;

import com.ysd.common.utils.PageUtils;
import com.ysd.common.utils.R;
import com.ysd.gulimall.order.controller.OrderController;
import com.ysd.gulimall.order.entity.OrderEntity;
import com.ysd.gulimall.order.entity.OrderItemEntity;
import com.ysd.gulimall.order.service.OrderItemService;
import com.ysd.gulimall.order.service.OrderService;
import org.bouncycastle.math.raw.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MemberOrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    OrderItemService orderItemService;
    @Autowired
    OrderController orderController;
    @GetMapping("/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, Model model){
        Map<String,Object> page=new HashMap<>();
        page.put("page",pageNum.toString());
        R r = orderController.listWithItem(page);
        model.addAttribute("orders",r);
        return "memberOrder";
    }
    
    @GetMapping("/detail.html")
    public String toDetail(Long id,Long osn,Model model){
        System.out.println(id);
        OrderEntity order = orderService.getById(id);
        List<OrderItemEntity> ods=orderItemService.getByOrderId(osn);
        model.addAttribute("ods",ods);
        System.out.println(ods);
        model.addAttribute("order",order);
        return "detail";
    }
    @GetMapping("/deleteById")
    public String deleteById(Long id){
        OrderEntity order = orderService.getById(id);
        order.setDeleteStatus(1);
        orderService.saveOrUpdate(order);
        System.out.println("===========>"+order);
        return "redirect:http://localhost:9000/memberOrder.html";
    }

}
